package com.test.controller;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.test.R;

/**
 * 滚动条
 */
public class ScrollBarActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn_up, btn_down;

    private ScrollView scrollView;

    private TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scroll_bar_demo);
        // 调用方法
        bindViewShow();
    }

    /**
     * 主要的业务逻辑
     */
    private void bindViewShow() {
        btn_up = findViewById(R.id.btn_up);
        btn_down = findViewById(R.id.btn_down);
        scrollView = findViewById(R.id.sl_key);
        textView = findViewById(R.id.tv_show);

        btn_up.setOnClickListener(this);
        btn_down.setOnClickListener(this);

        StringBuilder str = new StringBuilder();

        for (int i = 0; i < 100; i++) {
            str.append("测十数据第：" + i + "  条" + "\n");
        }
        textView.setText(str);
    }

    /**
     * 点击事件（滑动逻辑）
     * @param view
     */
    @Override
    public void onClick(View view) {

        // switch case 语句
        switch (view.getId()) {
            case R.id.btn_up:
                scrollView.fullScroll(scrollView.FOCUS_UP);
                break;
            case R.id.btn_down:
                scrollView.fullScroll(scrollView.FOCUS_DOWN);
                break;
        }

        // if else 语句
        //判断 若果获得的id是最顶部.则点击给他最顶部
//        if (view.getId() == btn_up.getId()) {
//            scrollView.fullScroll(scrollView.FOCUS_UP);
//            Toast.makeText(this, "测试if语句  滑动最顶部", Toast.LENGTH_LONG).show();
//        } else {
//            scrollView.fullScroll(scrollView.FOCUS_DOWN);
//            Toast.makeText(this, "测试if语句  滑动最底部", Toast.LENGTH_LONG).show();
//        }

    }
}
